'''
Created on Feb 5, 2011

@author: inyaky
'''
from google.appengine.ext.webapp import template
from view.renderers.uRenderable import Renderable
import uConst
import os
from model.uUserAdapter import UserAdapter

class NewCategoryRen(Renderable):
    
    def __init__(self, aCatName ,aFieldQuantity, aEnviroment):
        self._categoryName = aCatName
        self._fieldQuantity= aFieldQuantity
        self._enviroment = aEnviroment
    
    
    def render(self):
        
        user = UserAdapter(self._enviroment)
        
        fields = []
        for i in range(self._fieldQuantity):
            fields = fields + [{'name':"field" + str(i), 'typeName':"type" + str(i)}]
            
        types = []
        types = types + [{'name':uConst.DATETIME_TASK_FIELD_NAME ,'value':uConst.DATETIME_TASK_FIELD }]
        types = types + [{'name':uConst.EMAIL_TASK_FIELD_NAME ,'value':uConst.EMAIL_TASK_FIELD }]
        types = types + [{'name':uConst.FLOAT_TASK_FIELD_NAME ,'value':uConst.FLOAT_TASK_FIELD }]
        types = types + [{'name':uConst.INTEGER_TASK_FIELD_NAME ,'value':uConst.INTEGER_TASK_FIELD }]
        types = types + [{'name':uConst.PHONE_TASK_FIELD_NAME ,'value':uConst.PHONE_TASK_FIELD }]
        types = types + [{'name':uConst.STRING_TASK_FIELD_NAME,'value':uConst.STRING_TASK_FIELD }]
        types = types + [{'name':uConst.TEXT_TASK_FIELD_NAME,'value':uConst.TEXT_TASK_FIELD }]
        types = types + [{'name':uConst.DEADLINE_TASK_FIELD_NAME,'value':uConst.DEADLINE_TASK_FIELD }]
            
        category_list = []
        for aCategory in user.getCategoryList():
            category_list = category_list + aCategory.toRenderable()
        
        values = {
                           'draw_category_creater': True,
                           'category_name': self._categoryName,
                           'fields': fields,
                           'types': types,
                           'field_quantity': self._fieldQuantity,
                           'user':user.toRenderable(),
                           'category_list':category_list,
        }
        
        path = os.path.join(self._enviroment.path, uConst.INDEX)
        self._enviroment.response.out.write(template.render(path, values))
        
        
        
